﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
//using Microsoft.AspNet.SignalR;
using Newtonsoft.Json;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Configuration;
using System.Xml;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Net;
using HtmlAgilityPack;
namespace VideoGiaitri
{
    public partial class crawlImage : System.Web.UI.Page
    {
        public struct Video
        {
            public string title;
            public string link;
            public string image;
            public string domain;
            public string fullcontent;
            public string date;
            public string dateid;
        }
        public static Video[] arrVideo = new Video[5000];
        public struct Music
        {
            public string title;
            public string author;            
            public string image;
            public string ranking;
            public string point;
            public string domain;
            public string link;            
            public string fullcontent;
            public string date;
            public string dateid;
        }
        public static Music[] arrMusic = new Music[5000];
        public struct Game
        {
            public string title;
            public string link;
            public string image;
            public string domain;
            public string fullcontent;
            public string typegame;
            public string date;
            public string dateid;
        }
        public static Game[] arrGame = new Game[5000];

        public static int Length = 0;
        public static string[] UrlLinkVideo = new string[] { "http://haivl.tv", "http://chatvl.com", "http://vntube.tv", "http://dechtv.com" };//"http://dechtv.com/new/4.html", "http://dechtv.com/new/3.html", "http://dechtv.com/new/2.html", "http://chatvl.com/new/4", "http://chatvl.com/new/3", "http://chatvl.com/new/2", "http://haivl.tv/new/4", "http://haivl.tv/new/3", "http://haivl.tv/new/2", 
        public static string[] UrlDomainVideo = new string[] { "http://haivl.tv", "http://chatvl.com", "http://vntube.tv", "http://dechtv.com" };//  "http://dechtv.com", "http://dechtv.com", "http://dechtv.com", "http://chatvl.com", "http://chatvl.com", "http://chatvl.com", "http://haivl.tv", "http://haivl.tv", "http://haivl.tv", 
        public static string[] UrlLinkMusic = new string[] { "http://nhacso.net/bxh/top30.html"};
        public static string[] UrlDomainMusic = new string[] { "http://nhacso.net"};
        public static string[] UrlLinkGameAoe = new string[] { "http://chimsedinang.com/","http://aoe.gametv.vn" };
        public static string[] UrlDomainGameAoe = new string[] { "http://chimsedinang.com/", "http://gametv.vn" };
        public static string[] UrlLinkGameLmht = new string[] { "http://www.xemgame.com/videos/lien-minh-huyen-thoai-clip", "http://videogame.vn/chien-thuat/lien-minh-huyen-thoai.html","http://kenhlmht.com/" };
        public static string[] UrlDomainGameLmht = new string[] { "http://www.xemgame.com", "http://videogame.vn", "http://kenhlmht.com" };
        SqlConnection con = null;
        protected RunbatchImage CurrentBatchRunImage
        {
            get { return (RunbatchImage)this.Application["CurrentBatchRunImage"]; }
            set { this.Application["CurrentBatchRunImage"] = value; }
        }
        //IHubContext context = GlobalHost.ConnectionManager.GetHubContext<Hubs.ync>();
        RunbatchImage currentBatch;
        protected void Page_Load(object sender, EventArgs e)
        {
            //string content = Rss.getContent("http://feedly.com/#subscription%2Ffeed%2Fhttp%3A%2F%2Ffeeds.reuters.com%2Freuters%2FbusinessNews");

            if (!IsPostBack)
            {
                //Thời gian bắt đầu và kết thúc Crawl, hiện thời gian này chưa chuẩn
                //Mặc dù để 1000 năm nó vẫn bị ngừng, chưa điều tra ra
                this.txtStartDate.Text = DateTime.Today.AddMonths(-1).ToShortDateString();
                //this.txtEndDate.Text = this.txtStartDate.Text;
                this.txtEndDate.Text = DateTime.Today.AddYears(1000).ToShortDateString();
            }
            
            Response.Write(DateTime.Now.ToUniversalTime().ToString() + "<br>");
            Response.Write(DateTime.Now.ToString());
            SetBatchParameterTableVisibility(false);

            if (!CurrentBatchInProgress())
            {
                CurrentBatchRunImage = new RunbatchImage();

                this.lblPercentage.Text = "0";
                this.lblTimeRemaining.Text = "Unknown";
                var ts = new ThreadStart(RunBatch);
                var thread = new Thread(ts);
                thread.Start();
            }
            else
            {
                ShowAlert("Statement Batch Already In Progress");
            }

        }
        //Bắt đầu chạy Crawl
        protected void btnRunBatch_Click(object sender, EventArgs e)
        {
            //SetBatchParameterTableVisibility(false);

            //if (!CurrentBatchInProgress())
            //{
            //    CurrentBatchRunImage = new RunbatchImage();

            //    this.lblPercentage.Text = "0";
            //    this.lblTimeRemaining.Text = "Unknown";
            //    var ts = new ThreadStart(RunBatch);
            //    var thread = new Thread(ts);
            //    thread.Start();
            //}
            //else
            //{
            //    ShowAlert("Statement Batch Already In Progress");
            //}
            //timerBatchRun.Enabled = true;
        }
        //Chạy Crawl trong vòng lặp
        private void RunBatch()
        {
            DateTime startDate = DateTime.Parse(this.txtStartDate.Text);
            DateTime endDate = DateTime.Parse(this.txtEndDate.Text);

            var tempDate = startDate;
            int i = 0;
            while (tempDate < endDate)
            {
                i++;
                tempDate = tempDate.AddHours(1);
            }

            CurrentBatchRunImage.TotalNumberOfItems = i;
            CurrentBatchRunImage.Start();
            CurrentBatchRunImage.getInfo = "Tong so vong lap la" + CurrentBatchRunImage.TotalNumberOfItems;
            tempDate = startDate;
            while (tempDate < endDate)
            {
                //Hàm này chạy liên tục để crawl tin tức
                CurrentBatchRunImage.getInfo = "Dang chay vong lap " + CurrentBatchRunImage.ItemsCompleted + "/" + CurrentBatchRunImage.TotalNumberOfItems;
                DoSomething(new Random().Next(1, 5));
                tempDate = tempDate.AddHours(1);
                if (CurrentBatchRunImage == null || CurrentBatchRunImage.ShouldStop)
                {
                    break;
                }
                CurrentBatchRunImage.IncrementItemsCompleted();
            }
        }

        private string vN(string n)
        {
            return "N'" + n + "'";//System.Web.HttpUtility.HtmlEncode();
        }
        private string vNE(string n)
        {
            return "N'" + System.Web.HttpUtility.HtmlEncode(n) + "'";//System.Web.HttpUtility.HtmlEncode();
        }
        private string removeSpecialChar(string input)
        {
            input = input.Replace(":", "").Replace(",", "").Replace("_", "").Replace("'", "").Replace("\"", "").Replace(";", "");
            return input;
        }
        //Lấy ra các tin ở Data, Ghi ra SiteMap.xml
        private void generateSiteMap()
        {
            try
            {
                CurrentBatchRunImage.getInfo = "Ghi ra siteMap";
                //showProcessCrawl();
                
                XmlWriterSettings settings = null;
                string xmlDoc = null;
                string query = "select top 300 ";

                
                settings = new XmlWriterSettings();
                settings.Indent = true;
                settings.Encoding = Encoding.UTF8;
                xmlDoc = HttpRuntime.AppDomainAppPath + "sitemap.xml";

                float percent = 0.85f;
                int datetimeid = Uti.datetimeid();
               

                using (XmlTextWriter writer = new XmlTextWriter(xmlDoc, Encoding.UTF8))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("urlset");
                    writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");

                    writer.WriteStartElement("url");
                    writer.WriteElementString("loc", Uti.domain+"/Home/Video");                  
                    writer.WriteElementString("changefreq", "always");
                    writer.WriteElementString("priority", "1");
                    writer.WriteEndElement();
                    writer.WriteStartElement("url");
                    writer.WriteElementString("loc", Uti.domain + "/Home/Aoe");
                    writer.WriteElementString("changefreq", "always");
                    writer.WriteElementString("priority", "1");
                    writer.WriteEndElement();
                    openConn();
                    SqlCommand SC = new SqlCommand();
                    SC.Connection = con;
                    SqlDataReader DR = null;
                    query = " select top 10000 * from videogiaitri order by date desc";                   
                    SC.CommandText = query;
                    DR = SC.ExecuteReader();
                    while (DR.Read())
                    {
                        
                        try
                        {
                            writer.WriteStartElement("url");
                            writer.WriteElementString("loc", Uti.domain + "/Home/Xem/" + DR["id"].ToString());
                            //writer.WriteElementString("lastmod", DR["datetime"].ToString());
                            writer.WriteElementString("changefreq", "monthly");
                            try
                            {
                                percent = 0.85f;
                                //percent = percent + (int.Parse(DR["dateid"].ToString()) - datetimeid) * 0.01f;
                            }
                            catch (Exception ex)
                            {
                            }
                            writer.WriteElementString("priority", percent.ToString("0.00"));
                            writer.WriteEndElement();
                        }
                        catch (Exception ex2)
                        {
                        }
                    }
                    DR.Close();
                    query = " select top 10000 * from topgame order by date desc";
                    SC.CommandText = query;
                    DR = SC.ExecuteReader();
                    while (DR.Read())
                    {

                        try
                        {
                            writer.WriteStartElement("url");
                            writer.WriteElementString("loc", Uti.domain + "/Home/AoeXem/" + DR["id"].ToString());                            
                            writer.WriteElementString("changefreq", "monthly");
                            try
                            {
                                percent = 0.98f;
                                percent = percent + (int.Parse(DR["dateid"].ToString()) - datetimeid) * 0.01f;
                            }
                            catch (Exception ex)
                            {
                            }
                            writer.WriteElementString("priority", percent.ToString("0.00"));
                            writer.WriteEndElement();
                        }
                        catch (Exception ex2)
                        {
                        }
                    }
                    DR.Close();
                    writer.WriteEndElement();
                    writer.WriteEndDocument();
                    closeConn();
                }
               
                
            }
            catch (Exception extry) {
                CurrentBatchRunImage.getInfo = "Ghi ra siteMap, bi loi " + extry.ToString();
            }
        }
        private void openConn()
        {
            try
            {
                if (con == null || (con != null && con.State.ToString() == "Closed"))
                {
                    if (con == null)
                    {
                        con = new SqlConnection();
                        con.ConnectionString = "Server=42.112.31.145;Database=tinviet_vietnam;User Id=sa;Password=Huynguyenviet13071980;";

                        //"Server=Huynv\\Local;Database=diemtinvietnam;User Id=sa;Password=111111;";
                        //"Server=SQL5006.myWindowsHosting.com;Database=DB_9ACF33_diemtin;User Id=DB_9ACF33_diemtin_admin;Password=chanhniem;";
                    }
                    //"Server=Huynv\\Local;Database=timeline;User Id=sa;Password=111111;";
                    //"Server=SQL5004.myWindowsHosting.com;Database=DB_9AAE99_timeline;User Id=DB_9AAE99_timeline_admin;Password=Huynguyenviet1;";
                    //"Server=SQL5004.myWindowsHosting.com;Database=DB_9AAE99_timeline;User Id=DB_9AAE99_timeline_admin;Password=Huynguyenviet1;";

                    con.Open();
                }
                //CurrentBatchRun.getInfo = "Open Sql OK";
            }
            catch (Exception ex)
            {
                //CurrentBatchRun.getInfo = "Open Sql not OK" + ex.ToString();
            }
        }
        private void closeConn()
        {
            try
            {
                if (con != null && con.State.ToString() == "Open")
                {
                    con.Close();
                    //con = null;
                }
            }
            catch (Exception ex) { 
            }
        }
        private void crawlMusic()
        {
            openConn();
            SqlCommand SC = new SqlCommand();
            SC.Connection = con;
            arrMusic = new Music[5000];
            Length = 0;
            CurrentBatchRunImage.getInfo = "Bắt đầu craw" + UrlLinkMusic.Length + "," + UrlDomainMusic.Length;
            for (int i = 0; i < UrlDomainMusic.Length; i++)
            {
                try
                {
                    getAllLinkMusic(UrlDomainMusic[i], UrlLinkMusic[i]);
                }
                catch (Exception exitem)
                {
                }
            }//for i
            for (int i = 0; i < Length; i++)
            {
                arrMusic[i].fullcontent = Uti.getFullContentMusic(arrMusic[i].link);
                if (arrMusic[i].fullcontent.Trim().Equals("")) continue;
                string query = "";
                string condition = " where link='" + arrMusic[i].link + "' ";
                query = "if exists(select * from topmusic " + condition + ") ";
                query += " begin ";
                query += "    update topmusic set title=" + vN(arrMusic[i].title) + ",image='" + arrMusic[i].image + "',fullContent=" + vNE(arrMusic[i].fullcontent) + ",author=" + vN(arrMusic[i].author) + ",ranking=" + arrMusic[i].ranking + ",point=" + vN(arrMusic[i].point) + " where link='" + arrMusic[i].link + "'";
                query += "  ";
                query += " end ";
                query += " else ";
                query += " begin ";
                query += "    insert into topmusic(title,link,image,domain,fullContent,date,dateid,author,ranking,point) values(" + vN(arrMusic[i].title) + ",'" + arrMusic[i].link + "','" + arrMusic[i].image + "','" + arrMusic[i].domain + "'," + vNE(arrMusic[i].fullcontent) + ",N'" + arrMusic[i].date + "'," + arrMusic[i].dateid + "," + vN(arrMusic[i].author) + "," + arrMusic[i].ranking + "," + arrMusic[i].point + ")";
                query += "end ";
                try
                {
                    SC.CommandText = query;
                    SC.ExecuteNonQuery();
                }
                catch (Exception exquery)
                {

                }
            }
            closeConn();
        }

        private void crawlVideo() {
            try
            {
                openConn();
                SqlCommand SC = new SqlCommand();
                SC.Connection = con;

                arrVideo = new Video[5000];
                Length = 0;
                CurrentBatchRunImage.getInfo = "Bắt đầu craw" + UrlLinkVideo.Length + "," + UrlDomainVideo.Length;
                showBatchRunProcess();
                for (int i = 0; i < UrlDomainVideo.Length; i++)
                {
                    try
                    {
                        getAllLinkVideo(UrlDomainVideo[i], UrlLinkVideo[i]);
                    }
                    catch (Exception exitem)
                    {
                    }
                }//for i
                for (int i = 0; i < Length; i++)
                {
                    arrVideo[i].fullcontent = Uti.getFullContentVideo(arrVideo[i].link);
                    if (arrVideo[i].fullcontent.Trim().Equals("")) continue;
                    string query = "";
                    string condition = " where link='" + arrVideo[i].link + "' ";
                    query = "if exists(select * from videogiaitri " + condition + ") ";
                    query += " begin ";
                    query += "    update videogiaitri set title=" + vN(arrVideo[i].title) + ",image='" + arrVideo[i].image + "',fullContent=" + vNE(arrVideo[i].fullcontent) + " where link='" + arrVideo[i].link + "'";
                    query += "  ";
                    query += " end ";
                    query += " else ";
                    query += " begin ";
                    query += "    insert into videogiaitri(title,link,image,domain,fullContent,date,dateid) values(" + vN(arrVideo[i].title) + ",'" + arrVideo[i].link + "','" + arrVideo[i].image + "','" + arrVideo[i].domain + "'," + vNE(arrVideo[i].fullcontent) + ",N'" + arrVideo[i].date + "'," + arrVideo[i].dateid + ")";
                    query += "end ";
                    try
                    {
                        SC.CommandText = query;
                        SC.ExecuteNonQuery();
                    }
                    catch (Exception exquery)
                    {

                    }
                    CurrentBatchRunImage.getInfo = "Đang chèn tin " + i;
                    showBatchRunProcess();
                }
                closeConn();
            }
            catch (Exception exmain) {
                closeConn();
            }
        }
        private void crawlGameAoe() {
            try
            {
                openConn();
                SqlCommand SC = new SqlCommand();
                SC.Connection = con;

                arrGame = new Game[5000];
                Length = 0;
                CurrentBatchRunImage.getInfo = "Bắt đầu craw" + UrlLinkGameAoe.Length + "," + UrlDomainGameAoe.Length;
                for (int i = 0; i < UrlDomainGameAoe.Length; i++)
                {
                    try
                    {
                        getAllLinkGameAoe(UrlDomainGameAoe[i], UrlLinkGameAoe[i], 1);
                    }
                    catch (Exception exitem)
                    {
                    }
                }//for i
                for (int i = 0; i < Length; i++)
                {
                    arrGame[i].fullcontent = Uti.getFullContentGame(arrGame[i].link);
                    if (arrGame[i].fullcontent.Trim().Equals("")) continue;
                    string query = "";
                    string condition = " where link='" + arrGame[i].link + "' ";
                    query = "if exists(select * from topgame " + condition + ") ";
                    query += " begin ";
                    query += "    update topgame set title=" + vN(arrGame[i].title) + ",image='" + arrGame[i].image + "',fullContent=" + vNE(arrGame[i].fullcontent) + " where link='" + arrGame[i].link + "'";
                    query += "  ";
                    query += " end ";
                    query += " else ";
                    query += " begin ";
                    query += "    insert into topgame(title,link,image,domain,fullContent,date,dateid,typegame) values(" + vN(arrGame[i].title) + ",'" + arrGame[i].link + "','" + arrGame[i].image + "','" + arrGame[i].domain + "'," + vNE(arrGame[i].fullcontent) + ",N'" + arrGame[i].date + "'," + arrGame[i].dateid + "," + arrGame[i].typegame + ")";
                    query += "end ";
                    try
                    {
                        SC.CommandText = query;
                        SC.ExecuteNonQuery();
                    }
                    catch (Exception exquery)
                    {

                    }
                }
                closeConn();
            }
            catch (Exception exmain) { 
            }
        }
        private void crawlGameLmht()
        {
            try
            {
                openConn();
                SqlCommand SC = new SqlCommand();
                SC.Connection = con;

                arrGame = new Game[5000];
                Length = 0;
                CurrentBatchRunImage.getInfo = "Bắt đầu craw " + UrlLinkGameLmht.Length + "," + UrlDomainGameLmht.Length;
                for (int i = 0; i < UrlDomainGameLmht.Length; i++)
                {
                    try
                    {
                        getAllLinkGameLmht(UrlDomainGameLmht[i], UrlLinkGameLmht[i], 2);
                    }
                    catch (Exception exitem)
                    {
                    }
                }//for i
                for (int i = 0; i < Length; i++)
                {
                    arrGame[i].fullcontent = Uti.getFullContentGame(arrGame[i].link);
                    if (arrGame[i].fullcontent.Trim().Equals("")) continue;
                    string query = "";
                    string condition = " where link='" + arrGame[i].link + "' ";
                    query = "if exists(select * from topgame " + condition + ") ";
                    query += " begin ";
                    query += "    update topgame set title=" + vN(arrGame[i].title) + ",image='" + arrGame[i].image + "',fullContent=" + vNE(arrGame[i].fullcontent) + " where link='" + arrGame[i].link + "'";
                    query += "  ";
                    query += " end ";
                    query += " else ";
                    query += " begin ";
                    query += "    insert into topgame(title,link,image,domain,fullContent,date,dateid,typegame) values(" + vN(arrGame[i].title) + ",'" + arrGame[i].link + "','" + arrGame[i].image + "','" + arrGame[i].domain + "'," + vNE(arrGame[i].fullcontent) + ",N'" + arrGame[i].date + "'," + arrGame[i].dateid + "," + arrGame[i].typegame + ")";
                    query += "end ";
                    try
                    {
                        SC.CommandText = query;
                        SC.ExecuteNonQuery();
                    }
                    catch (Exception exquery)
                    {

                    }
                }
                closeConn();
            }
            catch (Exception exmain) {
                closeConn();
            }
        }
        private void crawlGame()
        {
            crawlGameLmht();
            crawlGameAoe();
        }
        private void crawlWord()
        {
            StreamReader SR = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "3000.txt");
            StringBuilder SB2 = new StringBuilder();
            while (!SR.EndOfStream) {
                SB2.Append("\"" + SR.ReadLine().Replace("\"", "") + "\",");//Replace("'", "").Replace("ˈ", "").Replace("´", "").
            }
            SR.Close();
            StreamWriter SW2 = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "Phase.txt");
            SW2.WriteLine(SB2.ToString());
            SW2.Close();
            return;
            string area = "";
            string area2 = "";
            StringBuilder SB=new StringBuilder();


            area = "//div[contains(@id,'entrylist1')]";
            area2 = ".//li[contains(@class,'')]";
            WebClient webClient = new WebClient();
            
            string[] url = new string[] { "http://www.oxfordlearnersdictionaries.com/wordlist/english/oxford3000/ox3k_A-B/", "http://www.oxfordlearnersdictionaries.com/wordlist/english/oxford3000/ox3k_C-D/", "http://www.oxfordlearnersdictionaries.com/wordlist/english/oxford3000/ox3k_E-G/", "http://www.oxfordlearnersdictionaries.com/wordlist/english/oxford3000/ox3k_H-K/", "http://www.oxfordlearnersdictionaries.com/wordlist/english/oxford3000/ox3k_L-N/", "http://www.oxfordlearnersdictionaries.com/wordlist/english/oxford3000/ox3k_O-P/", "http://www.oxfordlearnersdictionaries.com/wordlist/english/oxford3000/ox3k_Q-R/", "http://www.oxfordlearnersdictionaries.com/wordlist/english/oxford3000/ox3k_S/", "http://www.oxfordlearnersdictionaries.com/wordlist/english/oxford3000/ox3k_T/", "http://www.oxfordlearnersdictionaries.com/wordlist/english/oxford3000/ox3k_U-Z/"};
            CurrentBatchRunImage.getInfo = "Bắt đầu craw" + UrlLinkGameAoe.Length + "," + UrlDomainGameAoe.Length;
            for (int i = 0; i < url.Length; i++)
            {
                try
                {
                    for (int j = 1; j <= 7; j++) {
                        try
                        {
                            HtmlWeb hw = new HtmlWeb();
                            HtmlDocument doc = hw.Load(url[i] + "?page=" + j);
                            foreach (HtmlNode AllNode in doc.DocumentNode.SelectNodes(area))
                            {
                                foreach (HtmlNode node1 in AllNode.SelectNodes(area2))
                                {
                                    string word = node1.SelectSingleNode(".//a[contains(@class,'')]").InnerText;
                                    SB.Append("\""+word+"\",");
                                    string link=node1.SelectSingleNode(".//span[contains(@class,'soundList')]").SelectSingleNode(".//div[contains(@class,'')]").Attributes["data-src-ogg"].Value;
                                    string fileName = word.Replace(" ", "_").Replace(".", "_").Replace("-", "_").Replace(":", "_").Replace("'", "_").Replace(",", "_").Replace("\"", "_").Replace(";", "_").ToLowerInvariant();
                                    fileName += "_m";
                                    if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "/Word/new/" + fileName + ".ogg"))
                                    {
                                        webClient.DownloadFile(link, AppDomain.CurrentDomain.BaseDirectory+"/Word/new/" + fileName + ".ogg");
                                    }
                                     
                                }
                            }
                        }
                        catch (Exception ex2) { 
                        }
                    }
                }
                catch (Exception exitem)
                {
                }
            }//for i
            StreamWriter SW = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory+"/Dic.txt");
            SW.WriteLine(SB.ToString());
            SW.Close();
        }
        //Hàm này chạy liên tục để crawl tin tức
        private void DoSomething(int seconds)
        {
            DateTime nowDate = DateTime.Now;
            
            //SqlDataReader DR = null;
            Thread.Sleep(seconds * 5000);
            try
            {
                //crawlWord();
                //crawlMusic();
                DateTime endTime=DateTime.Now;
                DateTime startTime = DateTime.Now;
                string howLong = "";
                howLong += " Start at " + DateTime.Now.ToString() + " \r\n";
                crawlVideo();
                endTime = DateTime.Now;
                howLong += Uti.getDiffTimeMinuteFromTwoDate(startTime, endTime) + " Crawl Video Done \r\n";
                startTime = DateTime.Now;
                crawlGame();
                endTime = DateTime.Now;
                howLong += Uti.getDiffTimeMinuteFromTwoDate(startTime, endTime) + " Crawl Game Done \r\n";
                startTime = DateTime.Now;
                generateSiteMap();
                endTime = DateTime.Now;
                howLong += Uti.getDiffTimeMinuteFromTwoDate(startTime, endTime) + " siteMap Done \r\n";
                startTime = DateTime.Now;
                string callService = "";
                try
                {
                    string abc = getContent("http://diemtinvietnam.vn/adminYouKnow.aspx");
                    if (abc.Contains("Batch Runner Example"))
                    {
                        callService = "call service diemtinvietnam ok";
                    }
                    abc = getContent("http://thetopnews.net/crawl.aspx");
                    if (abc.Contains("Batch Runner Example"))
                    {
                        callService += ", call service thetopnews ok";
                    }
                }
                catch (Exception ex)
                {

                }
                endTime = DateTime.Now;
                howLong += Uti.getDiffTimeMinuteFromTwoDate(startTime, endTime) + "," + callService + " \r\n";
                startTime = DateTime.Now;
                howLong += " Ended at " + DateTime.Now.ToString() + " \r\n";
                StreamWriter SW = new StreamWriter(HttpRuntime.AppDomainAppPath + "HowLong.txt");
                SW.WriteLine(howLong);
                SW.Close();
                CurrentBatchRunImage.getInfo = "Đã xong, Bắt đầu lại";
            }
            catch (Exception ex)
            {
                //DR.Close();
                closeConn();
                CurrentBatchRunImage.getInfo = "Do SomeThing error.." + ex.ToString();

            }
        }
        
        public static void getAllLinkVideo(string mdomain,string url)
        {
            string area = "";
            string area2 = "";
           
            if (mdomain.Contains("http://haivl.tv"))
            {
                //getHaiVlLink(mdomain, url);
                area = "//div[contains(@class,'videoList')]";
                area2 = ".//a[contains(@class,'')]";
                //area = "videoList";
            }            
            if (mdomain.Contains("http://chatvl.com"))
            {
                //getHaiVlLink(mdomain, url);
                area = "//div[contains(@id,'entries-content')]";
                area2 = ".//a[contains(@class,'')]";
                //area = "videoList";
            }
            if (mdomain.Contains("http://vntube.tv"))
            {
                //getHaiVlLink(mdomain, url);
                area = "//div[contains(@id,'content')]";
                area2 = ".//a[contains(@class,'')]";
                //area = "videoList";
            }
            if (mdomain.Contains("http://dechtv.com"))
            {
                //getHaiVlLink(mdomain, url);
                area = "//div[contains(@class,'thumb')]";
                area2 = ".//a[contains(@class,'')]";
                //area = "videoList";
            }
            
            HtmlWeb hw = new HtmlWeb();
            HtmlDocument doc = hw.Load(url);
            string title = "";
            string link = "";
            string image = "";
            string domain = mdomain;
            string fullcontent = "";
            foreach (HtmlNode AllNode in doc.DocumentNode.SelectNodes(area))
            {
                foreach (HtmlNode node1 in AllNode.SelectNodes(area2))
                {
                    title = "";
                    link = "";
                    image = "";
                    //domain = "";
                    fullcontent = "";
                    try
                    {
                        image = node1.SelectSingleNode(".//img[contains(@class,'')]").Attributes["src"].Value;
                        title = node1.SelectSingleNode(".//img[contains(@class,'')]").Attributes["alt"].Value;
                    }
                    catch (Exception ex2)
                    {
                    }
                   
                    if (!image.Equals("") && !title.Equals(""))
                    {
                        //title = node1.Attributes["title"].Value;
                        link = node1.Attributes["href"].Value;
                        if (!link.StartsWith("http://") && !link.StartsWith("www"))
                        {
                            link = domain + link;
                        }
                        if (mdomain.Contains("haivl")) title = System.Web.HttpUtility.HtmlDecode(title);
                        arrVideo[Length].title = title;
                        arrVideo[Length].link = link;
                        arrVideo[Length].image = image;
                        arrVideo[Length].domain = domain;
                        arrVideo[Length].date = DateTime.Now.ToString();
                        arrVideo[Length].dateid = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00");
                        Length++;

                    }
                }//foreach 1
            }//for allNode
        }
        public static void getAllLinkGameAoe(string mdomain, string url, int typegame)
        {
            string area = "";
            string area2 = "";

            if (mdomain.Contains("gametv.vn"))
            {
                //getHaiVlLink(mdomain, url);
                area = "//div[contains(@class,'section-box')]";
                area2 = ".//a[contains(@class,'')]";
                //area = "videoList";
            }
            else if (mdomain.Contains("chimsedinang.com"))
            {
                getAllLinkGameChimSeDiNang(mdomain, url, typegame);
                return;
            }
            

            HtmlWeb hw = new HtmlWeb();
            HtmlDocument doc = hw.Load(url);
            string title = "";
            string link = "";
            string image = "";
            string domain = mdomain;
            string fullcontent = "";
            foreach (HtmlNode AllNode in doc.DocumentNode.SelectNodes(area))
            {
                foreach (HtmlNode node1 in AllNode.SelectNodes(area2))
                {
                    title = "";
                    link = "";
                    image = "";
                    //domain = "";
                    fullcontent = "";
                    try
                    {
                        image = node1.SelectSingleNode(".//img[contains(@class,'')]").Attributes["src"].Value;
                        title = node1.SelectSingleNode(".//img[contains(@class,'')]").Attributes["alt"].Value;
                    }
                    catch (Exception ex2)
                    {
                    }

                    if (!image.Equals("") && !title.Equals(""))
                    {
                        //title = node1.Attributes["title"].Value;
                        link = node1.Attributes["href"].Value;
                        if (!link.StartsWith("http://") && !link.StartsWith("www"))
                        {
                            link = domain + link;
                        }
                        //if (mdomain.Contains("haivl")) title = System.Web.HttpUtility.HtmlDecode(title);
                        arrGame[Length].title = title;
                        arrGame[Length].link = link;
                        arrGame[Length].image = image;
                        arrGame[Length].domain = domain;
                        arrGame[Length].date = DateTime.Now.ToString();
                        arrGame[Length].dateid = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00");
                        arrGame[Length].typegame = typegame.ToString();
                        Length++;

                    }
                }//foreach 1
            }//for allNode
        }
        public static void getAllLinkGameLmht(string mdomain, string url, int typegame)
        {
            string area = "";
            string area2 = "";

            if (mdomain.Contains("xemgame.com"))
            {
                //getHaiVlLink(mdomain, url);
                area = "//div[contains(@class,'col-8 main-content')]";
                area2 = ".//a[contains(@class,'')]";
            }
            else if (mdomain.Contains("videogame.vn"))
            {
                getAllLinkGameVideoGame(mdomain,url,typegame);
                return;
            }
            else if (mdomain.Contains("kenhlmht.com"))
            {
                getAllLinkGameKenhlmht(mdomain, url, typegame);
                return;
            }

            HtmlWeb hw = new HtmlWeb();
            HtmlDocument doc = hw.Load(url);
            string title = "";
            string link = "";
            string image = "";
            string domain = mdomain;
            string fullcontent = "";
            foreach (HtmlNode AllNode in doc.DocumentNode.SelectNodes(area))
            {
                foreach (HtmlNode node1 in AllNode.SelectNodes(area2))
                {
                    title = "";
                    link = "";
                    image = "";
                    //domain = "";
                    fullcontent = "";
                    try
                    {
                        image = node1.SelectSingleNode(".//img[contains(@class,'')]").Attributes["src"].Value;
                        title = node1.SelectSingleNode(".//img[contains(@class,'')]").Attributes["alt"].Value;
                    }
                    catch (Exception ex2)
                    {
                    }

                    if (!image.Equals("") && !title.Equals(""))
                    {
                        //title = node1.Attributes["title"].Value;
                        link = node1.Attributes["href"].Value;
                        if (!link.StartsWith("http://") && !link.StartsWith("www"))
                        {
                            link = domain + link;
                        }
                        //if (mdomain.Contains("haivl")) title = System.Web.HttpUtility.HtmlDecode(title);
                        arrGame[Length].title = title;
                        arrGame[Length].link = link;
                        arrGame[Length].image = image;
                        arrGame[Length].domain = domain;
                        arrGame[Length].date = DateTime.Now.ToString();
                        arrGame[Length].dateid = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00");
                        arrGame[Length].typegame = typegame.ToString();
                        Length++;

                    }
                }//foreach 1
            }//for allNode
        }
        public static void getAllLinkGameChimSeDiNang(string mdomain, string url, int typegame)
        {
            string area = "";
            string area2 = "";

            if (mdomain.Contains("chimsedinang"))
            {
                //getHaiVlLink(mdomain, url);
                area = "//div[contains(@class,'videogame-tieubieu1 video-moi-nhat')]";
                area2 = ".//div[contains(@class,'ds-video')]";
                //area = "videoList";
            }


            HtmlWeb hw = new HtmlWeb();
            HtmlDocument doc = hw.Load(url);
            string title = "";
            string link = "";
            string image = "";
            string domain = mdomain;
            string fullcontent = "";
            foreach (HtmlNode AllNode in doc.DocumentNode.SelectNodes(area))
            {
                foreach (HtmlNode node1 in AllNode.SelectSingleNode(area2).SelectNodes(".//li[contains(@class,'ds-video-item')]"))
                {
                    title = "";
                    link = "";
                    image = "";
                    //domain = "";
                    fullcontent = "";                    
                    try
                    {
                        image = Uti.getImageSrc(node1.InnerHtml);//.SelectSingleNode("//img[contains(@class,'video-thumb lazy')]").Attributes["src"].Value;
                        title = node1.SelectSingleNode(".//div[contains(@class,'video-info-title')]").InnerText;
                    }
                    catch (Exception ex2)
                    {
                    }

                    if (!image.Equals("") && !title.Equals(""))
                    {
                        //title = node1.Attributes["title"].Value;
                        link = node1.SelectSingleNode(".//div[contains(@class,'video-info-title')]").SelectSingleNode(".//a[contains(@class,'')]").Attributes["href"].Value;
                        if (!link.StartsWith("http://") && !link.StartsWith("www"))
                        {
                            link = domain + link;
                        }
                        //if (mdomain.Contains("haivl")) title = System.Web.HttpUtility.HtmlDecode(title);
                        arrGame[Length].title = title;
                        arrGame[Length].link = link;
                        arrGame[Length].image = image;
                        arrGame[Length].domain = domain;
                        arrGame[Length].date = DateTime.Now.ToString();
                        arrGame[Length].dateid = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00");
                        arrGame[Length].typegame = typegame.ToString();
                        Length++;

                    }
                }//foreach 1
            }//for allNode
        }
        public static void getAllLinkGameVideoGame(string mdomain, string url, int typegame)
        {
            string area = "";
            string area2 = "";
            area = "//div[contains(@class,'ds-video')]";
            area2 = ".//div[contains(@id,'list-videos')]";

            HtmlWeb hw = new HtmlWeb();
            HtmlDocument doc = hw.Load(url);
            string title = "";
            string link = "";
            string image = "";
            string domain = mdomain;
            string fullcontent = "";
            foreach (HtmlNode AllNode in doc.DocumentNode.SelectNodes(area))
            {
                foreach (HtmlNode node1 in AllNode.SelectSingleNode(area2).SelectNodes(".//li[contains(@class,'ds-video-item')]"))
                {
                    title = "";
                    link = "";
                    image = "";
                    //domain = "";
                    fullcontent = "";
                    try
                    {
                        image = Uti.getImageSrc(node1.InnerHtml);//.SelectSingleNode("//img[contains(@class,'video-thumb lazy')]").Attributes["src"].Value;
                        title = node1.SelectSingleNode(".//div[contains(@class,'video-info-title')]").InnerText;
                    }
                    catch (Exception ex2)
                    {
                    }

                    if (!image.Equals("") && !title.Equals(""))
                    {
                        //title = node1.Attributes["title"].Value;
                        link = node1.SelectSingleNode(".//div[contains(@class,'video-info-title')]").SelectSingleNode(".//a[contains(@class,'')]").Attributes["href"].Value;
                        if (!link.StartsWith("http://") && !link.StartsWith("www"))
                        {
                            link = domain + link;
                        }
                        //if (mdomain.Contains("haivl")) title = System.Web.HttpUtility.HtmlDecode(title);
                        arrGame[Length].title = title;
                        arrGame[Length].link = link;
                        arrGame[Length].image = image;
                        arrGame[Length].domain = domain;
                        arrGame[Length].date = DateTime.Now.ToString();
                        arrGame[Length].dateid = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00");
                        arrGame[Length].typegame = typegame.ToString();
                        Length++;

                    }
                }//foreach 1
            }//for allNode
        }
        public static void getAllLinkGameKenhlmht(string mdomain, string url, int typegame)
        {
            string area = "";
            string area2 = "";
            area = "//div[contains(@id,'contentIndex')]";
            area2 = ".//div[contains(@class,'innerItem')]";

            HtmlWeb hw = new HtmlWeb();
            HtmlDocument doc = hw.Load(url);
            string title = "";
            string link = "";
            string image = "";
            string domain = mdomain;
            string fullcontent = "";
            foreach (HtmlNode AllNode in doc.DocumentNode.SelectNodes(area))
            {
                foreach (HtmlNode node1 in AllNode.SelectNodes(area2))
                {
                    title = "";
                    link = "";
                    image = "";
                    //domain = "";
                    fullcontent = "";
                    try
                    {
                        image = node1.SelectSingleNode(".//div[contains(@class,'wrap-inner-image')]").SelectSingleNode(".//img[contains(@class,'')]").Attributes["src"].Value;
                        title = node1.SelectSingleNode(".//div[contains(@class,'innerItemHeader')]").SelectSingleNode(".//h3[contains(@class,'')]").InnerText;
                        title = title.Replace("\n", "");
                        title = title.Replace("\t", "").Trim();
                    }
                    catch (Exception ex2)
                    {
                    }

                    if (!image.Equals("") && !title.Equals(""))
                    {
                        //title = node1.Attributes["title"].Value;
                        link = node1.SelectSingleNode(".//div[contains(@class,'innerItemHeader')]").SelectSingleNode(".//h3[contains(@class,'')]").SelectSingleNode(".//a[contains(@class,'')]").Attributes["href"].Value;
                        if (!link.StartsWith("http://") && !link.StartsWith("www"))
                        {
                            link = domain + link;
                        }
                        //if (mdomain.Contains("haivl")) title = System.Web.HttpUtility.HtmlDecode(title);
                        arrGame[Length].title = title;
                        arrGame[Length].link = link;
                        arrGame[Length].image = image;
                        arrGame[Length].domain = domain;
                        arrGame[Length].date = DateTime.Now.ToString();
                        arrGame[Length].dateid = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00");
                        arrGame[Length].typegame = typegame.ToString();
                        Length++;

                    }
                }//foreach 1
            }//for allNode
        }
        public static void getAllLinkMusic(string mdomain, string url)
        {
           
            if (mdomain.Contains("http://nhacso.net"))
            {

                getAllLinkNhacSoMusic(mdomain, url);
                return;    
            }
            
        }
        public static void getAllLinkNhacSoMusic(string mdomain, string url)
        {
            string area = "";
            string area2 = "";

           

            area = "//div[contains(@class,'list_topbh_2')]";
            area2 = ".//li[contains(@class,'')]";

            HtmlWeb hw = new HtmlWeb();
            HtmlDocument doc = hw.Load(url);
            string title = "";
            string link = "";
            string image = "";
            string domain = mdomain;
            string fullcontent = "";
            int No = 0;
            string point = "";
            string author = "";
            foreach (HtmlNode AllNode in doc.DocumentNode.SelectNodes(area))
            {
                foreach (HtmlNode node1 in AllNode.SelectNodes(area2))
                {
                    title = node1.SelectSingleNode(".//a[contains(@class,'')]").Attributes["title"].Value;
                    link = node1.SelectSingleNode(".//a[contains(@class,'')]").Attributes["href"].Value;
                    try
                    {
                        //if (No==0){
                        author = node1.SelectSingleNode("./div[contains(@class,'info')]").InnerHtml;//.SelectSingleNode("./h4").SelectSingleNode("./span[contains(@class,'xamnhat')]").SelectSingleNode("./a[contains(@class,'')]").InnerText;
                        //}else{
                            //author = node1.SelectSingleNode(".//div[contains(@class,'info_2')]").SelectSingleNode(".//span[contains(@class,'xamnhat')]").SelectSingleNode(".//a[contains(@class,'')]").InnerText;//.SelectSingleNode(".//h4[contains(@class,'')]").InnerText;
                        //}
                    }catch(Exception at){

                    }
                    try
                    {
                        point = node1.SelectSingleNode(".//div[contains(@class,'ln_top1')]").SelectSingleNode(".//label[contains(@class,'')]").InnerText;
                    }
                    catch (Exception ex)
                    {
                        point = "";
                    }
                    image = "";
                    //domain = "";
                    fullcontent = "";
                    try
                    {
                        image = node1.SelectSingleNode(".//div[contains(@class,'pics')]").SelectSingleNode(".//img[contains(@class,'')]").Attributes["src"].Value;
                        //title = node1.SelectSingleNode(".//img[contains(@class,'')]").Attributes["alt"].Value;
                    }
                    catch (Exception ex2)
                    {
                    }

                    if (!title.Equals(""))
                    {
                        //title = node1.Attributes["title"].Value;
                        //link = node1.Attributes["href"].Value;
                        No++;
                        if (!link.StartsWith("http://") && !link.StartsWith("www"))
                        {
                            link = domain + link;
                        }
                        //if (mdomain.Contains("haivl")) title = System.Web.HttpUtility.HtmlDecode(title);
                        arrMusic[Length].author = author;
                        arrMusic[Length].ranking = No.ToString();
                        arrMusic[Length].point = point;
                        arrMusic[Length].title = title;
                        arrMusic[Length].link = link;
                        arrMusic[Length].image = image;
                        arrMusic[Length].domain = domain;
                        arrMusic[Length].date = DateTime.Now.ToString();
                        arrMusic[Length].dateid = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00");
                        Length++;

                    }
                }//foreach 1
            }//for allNode
        }
        public static bool isVn(string content) {
            string[] code = new string[] { "á", "ả", "ã", "â", "ă", "à", "ạ", "ú", "ủ", "ũ", "ù", "ụ", "é", "ẻ", "ẽ", "ê", "è", "ẹ", "í", "ỉ", "ĩ", "ì", "ị", "ó", "ỏ", "õ", "ô", "ơ", "ò", "ọ", "ấ", "ẩ", "ẫ", "ầ", "ậ", "ắ", "ẳ", "ẵ", "ằ", "ặ", "ế", "ể", "ễ", "ề", "ệ", "ố", "ổ", "ỗ", "ồ", "ộ", "ớ", "ở", "ỡ", "ờ", "ợ", "ú", "ủ", "ũ", "ù", "ụ", "ý", "ỷ", "ỹ", "ỳ", "ỵ" };
            int count = 0;
            for(int i=0;i<code.Length;i++){
                if (content.ToLowerInvariant().Contains(code[i])) {
                    count++;
                    if (count>=2) return true;
                }
            }
            return false;
        }
        public static String getContent(String url)
        {
            String htmlCode = "";
            Random r = new Random();
            string[] myAngent = {"Chrome /36.0.1944.0",
                       "Chrome /35.0.1916.47",
                       "Firefox/29.0",                                              
                       "Chrome/32.0.1667.0",
                       "Chrome/32.0.1664.3",
                       "Chrome/28.0.1467.0",
                       "Chrome/28.0.1467.0",
                       "Firefox /31.0"};
            string[] arrProxy ={"177.47.94.66:8080",
                       "202.4.104.156:8080",
                       "190.221.160.190:3127",                                              
                       "27.147.141.194",
                       "118.97.158.26:8080",
                       "186.233.168.254:8080",
                       "79.143.188.37:3128",
                       "221.182.62.115:9999"};
            string[] arrUrl ={"http://www.kproxy.com/servlet/redirect.srv/ssb/sujxeqvjcykexcy/p1/Home/HotNews",
                              "http://www.free-web-proxy.de/@.php?u=3GZiH3A0g4E1TWkMR%2FMDlOAt%2FCKJSJhnMm5G%2BXP9FT7a&b=6",
                              "http://onlineproxyfree.com/index.php?q=aHR0cDovL2RpZW10aW52aWV0bmFtLnZuL0hvbWUvSG90TmV3cw%3D%3D",
                              "https://webproxy.vpnbook.com/browse.php?u=0FBEeZB1sMz2bWBcOG7WCpvJ5YQSW5bA7kTBvIe8FXlk&b=0"
                            };
            try
            {
                bool conti = true;
                byte stry = 0;
                WebResponse myResponse;
                StreamReader sr;
                do
                {
                    try
                    {
                        Random random = new Random();
                        int randomNumber = random.Next(0, myAngent.Length);
                        conti = false;
                        int randomUrl=random.Next(0,arrUrl.Length);
                        //string proxyAddress = arrProxy[random.Next(0, arrProxy.Length)];
                        //Uri newUri = new Uri(proxyAddress);
                        // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
                        //myProxy.Address = newUri;
                        //WebProxy myProxy = new WebProxy(proxyAddress);
                        //url=arrUrl[randomUrl];
                        HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
                        myRequest.Method = "GET";
                        myRequest.Timeout = 15000;
                        myRequest.UserAgent = myAngent[randomNumber];
                        //myRequest.Proxy = myProxy;
                        //myRequest.TransferEncoding = "UTF-8";
                        myResponse = myRequest.GetResponse();
                        sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);//.UTF8
                        htmlCode = sr.ReadToEnd();
                        sr.Close();
                        myResponse.Close();

                    }
                    catch (Exception err1)
                    {
                        conti = true;
                        stry++;
                    }
                } while (conti && stry < 3);
            }
            catch (Exception err)
            {
                return "";
            }

            return htmlCode;
        }
       
        private void SetBatchParameterTableVisibility(bool visible)
        {
            this.tblBatchParameters.Visible = visible;
            this.tblBatchProgress.Visible = !visible;
        }

        private bool CurrentBatchInProgress()
        {
            var RunbatchImage = CurrentBatchRunImage;
            if (RunbatchImage == null || RunbatchImage.HasNotBegun)
            {
                return false;
            }
            return !RunbatchImage.IsCompletedOrExpired;
        }

        protected void showBatchRunProcess()
        {
            currentBatch = CurrentBatchRunImage;
            if (currentBatch != null && currentBatch.HasNotBegun)
            {
                return;
            }
            if (currentBatch == null)
            {
                SetBatchParameterTableVisibility(true);
                return;
            }
            if (currentBatch.IsCompletedOrExpired)
            {
                if (currentBatch.ShouldStop)
                {
                    //ShowAlert(String.Format("Statement Run Completed at {0}, but was cancelled.", currentBatch.LastUpdatedTime));
                    this.lblInfo.Text = "Statement Run Completed at " + currentBatch.LastUpdatedTime + " but was cancelled.<br>";
                }
                else
                {
                    //ShowAlert(String.Format("Statement Run Completed at {0}.", currentBatch.LastUpdatedTime));
                    this.lblInfo.Text = "Statement Run Completed at " + currentBatch.LastUpdatedTime + "<br>";
                }
                //timerBatchRun.Enabled = false;
                SetBatchParameterTableVisibility(true);
            }
            else
            {
                this.lblPercentage.Text = currentBatch.PercentDone.ToString();
                this.lblTimeRemaining.Text = String.Format("{0:f2}", currentBatch.EstimatedTimeRemaining.TotalMinutes);
                this.lblInfo.Text = currentBatch.getInfo + "<br>";
                if (this.lblInfo.Text.Contains("Đã xong và chạy lại")) this.lblInfo.Text = "";
                //var context = GlobalHost.ConnectionManager.GetHubContext<Hubs.ync>();
                //context.Clients.All.addNewAll("xahoi", "Xin chao cac ban ok");  
            }
        }

        private void ShowAlert(string alert)
        {
            //Response.Write("<script>alert('" + alert + "')</script>");
            if (currentBatch != null) currentBatch.getInfo = alert;
            Response.Flush();
            showBatchRunProcess();
        }
        protected void btnStop_Click(object sender, EventArgs e)
        {
            ShowAlert("Batch Run Stopped");
            if (CurrentBatchRunImage != null)
            {
                CurrentBatchRunImage.ShouldStop = true;
                //this.timerBatchRun.Enabled = false;
                SetBatchParameterTableVisibility(true);
            }
        }
    }
}